package com.ruoyi.subject.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.subject.domain.QbSubjectItem;
import com.ruoyi.subject.service.IQbSubjectItemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 题项Controller
 *
 * @author lzhj
 * @date 2021-01-20
 */
@Api(tags = "题目-选项")
@RestController
@RequestMapping("/qb/subItem")
public class QbSubjectItemController extends BaseController {
    @Autowired
    private IQbSubjectItemService qbSubjectItemService;

//    /**
//     * 查询题项列表
//     */
//    @ApiOperation("查询题项列表。qb:subject:list'")
//    @PreAuthorize("@ss.hasPermi('qb:subItem:list')")
//    @GetMapping("/list")
//    public TableDataInfo list(QbSubjectItem qbSubjectItem)
//    {
//        startPage();
//        List<QbSubjectItem> list = qbSubjectItemService.selectQbSubjectItemList(qbSubjectItem);
//        return getDataTable(list);
//    }


//    /**
//     * 获取题项详细信息
//     */
//    @PreAuthorize("@ss.hasPermi('qb:subItem:query')")
//    @GetMapping(value = "/{id}")
//    public AjaxResult getInfo(@PathVariable("id") Long id)
//    {
//        return AjaxResult.success(qbSubjectItemService.selectQbSubjectItemById(id));
//    }

    /**
     * 根据题目id获取题项详细信息
     */
    @ApiOperation(value = "根据题目id获取题项详细信息，qb:subItem:query")
    @PreAuthorize("@ss.hasPermi('qb:subItem:query')")
    @GetMapping(value = "/getSubjectList/{subjectId}")
    public AjaxResult getSubjectList(@PathVariable("subjectId") Long subjectId) {
        List<QbSubjectItem> subjectItemList = qbSubjectItemService.selectQbSubjectItemBySubjectId(subjectId);
        return AjaxResult.success(subjectItemList);
    }

    /**
     * 新增题项
     */
    @ApiOperation(value = "新增题项，qb:subItem:add")
    @PreAuthorize("@ss.hasPermi('qb:subItem:add')")
    @Log(title = "题项", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QbSubjectItem qbSubjectItem) {
        return toAjax(qbSubjectItemService.insertQbSubjectItem(qbSubjectItem));
    }

    /**
     * 批量新增题项
     */
    @ApiOperation(value = "批量新增题项，qb:subItem:add")
    @PreAuthorize("@ss.hasPermi('qb:subItem:add')")
    @Log(title = "题项", businessType = BusinessType.INSERT)
    @PostMapping("/addBatch")
    public AjaxResult addBatch(@RequestBody List<QbSubjectItem> qbSubjectItems) {
        qbSubjectItemService.insertQbSubjectItemList(qbSubjectItems);
        return AjaxResult.success("保存成功");
    }

    /**
     * 修改题项
     */
    @ApiOperation(value = "修改题项，qb:subItem:edit")
    @PreAuthorize("@ss.hasPermi('qb:subItem:edit')")
    @Log(title = "题项", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QbSubjectItem qbSubjectItem) {
        return toAjax(qbSubjectItemService.updateQbSubjectItem(qbSubjectItem));
    }

    /**
     * 删除题项
     */
    @ApiOperation(value = "删除题项，qb:subItem:remove")
    @PreAuthorize("@ss.hasPermi('qb:subItem:remove')")
    @Log(title = "题项", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        qbSubjectItemService.deleteQbSubjectItemByIds(ids);
        return AjaxResult.success("删除成功");
    }
}
